﻿using System.Collections;
using System.Collections.Generic;
using BaseSyntax.Values.StringTest.Yaml.Configs;
using Newtonsoft.Json;

namespace BaseSyntax.Values.StringTest.Yaml.Parsers
{
	public static class ParserEntrance
	{
		static Dictionary<string, object> dUnity = new Dictionary<string, object>();
		static Dictionary<string, object> dCorona = new Dictionary<string, object>();
		
		public static void Parse(string fileId, Dictionary<string, object> parent)
		{
			
			var dic = dUnity[fileId] as Dictionary<string, object>;
			if (dic != null)
			{
				string uType = (string)dic["UType"];

				if (uType == "MonoBehaviour")
				{
					var mScript = dic["m_Script"] as Dictionary<string, object>;

					string guid = (string) mScript["guid"];
					
					uType = MonoGuidMap.GetMapper(guid);
				}
				
				// todo 
				IParser parser = ParserMap.GetMap(uType);

				if (parser != null)
				{
					parser.Parse(dUnity, fileId, parent, dCorona);
				}
			}
		}

		public static Dictionary<string, object> GetCoronaMap(Dictionary<string, object> dU)
		{
			dUnity = dU;
			dCorona = new Dictionary<string, object>();
			
			// 查找根节点
			string rootId = RootParser.GetRootId(dUnity);
			dCorona["rootId"] = rootId;
			
			Parse(rootId, dCorona);

			string data = JsonConvert.SerializeObject(dCorona);
			
			return dCorona;
		}
	}
}